package cn.com.kgo.entity.util;

import cn.com.kgo.entity.sys.SysParamsEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author keepgoon
 * @Description: TODO
 * @date 2019/6/416:11
 */
public class SysParams {
    private static List<SysParamsEntity> staticParams = new ArrayList <SysParamsEntity>();
    private static String defautGroup = "common-params";//系统默认分组

    /**
     * 获取参数
     * @param key
     * @return
     */
    public static String getParam(String key){
        if (StringUtils.isBlank(key))return null;
        for(SysParamsEntity thisParam : staticParams){
            if (thisParam.getGroup().equals(defautGroup)&&thisParam.getKey().equals(key)){
                return thisParam.getValue();
            }
        }
        return null;
    }
    /**
     * 根据分组和Key获取系统参数，如果分组为空，就根据默认分组查询
     * @param group
     * @param key
     * @return
     */
    public static String  getParam(String group,String key){
        if (StringUtils.isBlank(key))return null;
        group = StringUtils.isBlank(group)? defautGroup : group;
        for(SysParamsEntity thisParam : staticParams){
            if (thisParam.getGroup().equals(group)&&thisParam.getKey().equals(key)){
                return thisParam.getValue();
            }
        }
        return null;
    }
    /**
     * 获取所有分组
     * @param group
     * @return
     */
    public List<SysParamsEntity> getGroups(String group){
        group = StringUtils.isBlank(group)? defautGroup : group;
        List<SysParamsEntity> outList = new ArrayList <SysParamsEntity>();
        for(SysParamsEntity thisParam : staticParams){
            if (thisParam.getGroup().equals(group)){
               outList.add(thisParam);
            }
        }
        return outList;
    }








}
